package com.stylefeng.guns.modular.system.business.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.common.constant.Const;
import com.stylefeng.guns.common.persistence.dao.DeptMapper;
import com.stylefeng.guns.common.persistence.dao.DotMapper;
import com.stylefeng.guns.common.persistence.dao.UserMapper;
import com.stylefeng.guns.common.persistence.model.Dept;
import com.stylefeng.guns.common.persistence.model.Dot;
import com.stylefeng.guns.common.persistence.model.User;
import com.stylefeng.guns.core.base.tips.ErrorTip;
import com.stylefeng.guns.core.base.tips.SuccessTip;
import com.stylefeng.guns.core.base.tips.Tip;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.modular.system.business.service.IDotService;
import com.stylefeng.guns.modular.system.business.service.IUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiejie123
 * @since 2018-01-15
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Resource
    UserMapper userMapper;

    @Override
    public Tip updateUser(User user) {
        Wrapper<User> wrapper = new EntityWrapper<>();
        wrapper = wrapper.where("account={0} and status!=3  ", user.getAccount()).andNew("id !={0}",user.getId());
        int i=this.selectCount(wrapper);
        if(i>0){
            return new ErrorTip(Const.FAILUER,"账号已存在，请重新填写");
        }
        if(this.updateById(user)){
            return new SuccessTip();
        }else{
            return new ErrorTip(Const.FAILUER,"操作失败");
        }
    }
}
